<script>
  function calculate_payment(PV,IR,NP)
  {
    var PMT=(PV*IR)/(1-Math.pow(1+IR,-NP));
    return round_decimals(PMT,2);
  }

  function round_decimals(original_number,decimals)
  {
    var result1=original_number*Math.pow(10,decimals);
    var result2=Math.round(result1);
    return result2/Math.pow(10,decimals);
  }

  var present_value=200000;
  var interest_rate=0.09;
  var loan_term=30;
  var monthly_payment=calculate_payment(present_value,interest_rate/12,loan_term*12);
  document.write("Amout of the loan:\t$"+present_value+"<br>Annual interest rate:\t"+interest_rate*100+"%<br>"
                 +"Term of the loan:\t"+loan_term+" years<br><br>"+"Monthly payment:\t$"+monthly_payment);
</script>

